<template>
  <div>
    <!-- 面包屑导航区域 -->
    <div class="bread_box">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>角色列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索与添加区域 -->
      <el-form
        class="search_from"
        size="small"
        :inline="true"
        label-width="70px"
      >
        <el-form-item label="角色名称">
          <el-input placeholder="请输入角色名称"></el-input>
        </el-form-item>

        <el-form-item label="权限字符">
          <el-input placeholder="请输入权限字符"></el-input>
        </el-form-item>

        <el-form-item label="状态">
          <el-select placeholder="角色状态">
            <el-option label="正常" value="true"></el-option>
            <el-option label="停用" value="false"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="创建时间">
          <el-date-picker
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini">重置</el-button>
        </el-form-item>
      </el-form>

      <div>
        <el-button type="primary" icon="el-icon-plus" size="mini"
          >新增</el-button
        >
        <el-button type="success" icon="el-icon-edit" size="mini"
          >修改</el-button
        >
        <el-button type="danger" icon="el-icon-delete" size="mini"
          >删除</el-button
        >
        <el-button type="warning" icon="el-icon-download" size="mini"
          >导出</el-button
        >
      </div>
      <el-table
        ref="multipleTable"
        :data="roleList"
        tooltip-effect="dark"
        style="width: 100%"
        :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="roleName" label="角色名称"></el-table-column>
        <el-table-column label="权限字符">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.roleString === 'admin'" type="success">
              <span>admin</span>
            </el-tag>
            <el-tag v-else type="info">
              <span>common</span>
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="roleOrder" label="显示顺序"> </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.roleState"> </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="roleCreated" label="创建时间"></el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="text" size="mini"
              ><i class="el-icon-edit"></i><span>修改</span></el-button
            >
            <el-button type="text" size="mini"
              ><i class="el-icon-delete"></i><span>删除</span></el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[4, 8, 10, 20]"
        :page-size="4"
        layout="total, sizes, prev, pager, next, jumper"
        :total="2"
        background
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 角色列表
      roleList: [
        {
          id: 1, // 角色id
          roleName: '管理员', // 角色名称
          roleString: 'admin', // 权限字符
          roleOrder: 1, // 显示顺序
          roleState: true, // 权限状态
          roleCreated: '2020-06-10' // 创建时间
        },
        {
          id: 2, // 角色id
          roleName: '普通用户', // 角色名称
          roleString: 'common', // 权限字符
          roleOrder: 2, // 显示顺序
          roleState: true, // 权限状态
          roleCreated: '2020-06-12' // 创建时间
        }
      ]
    }
  },
  methods: {
    // 获得角色列表
    async getRoleList () {
      const { data: res } = await this.$http.get('/authority/selectRole')
      console.log('角色列表', res)
    },
    // 改变权限状态
    roleValidChanged (roleInfo) {
      console.log(roleInfo.roleState)
      roleInfo.roleState = !roleInfo.roleState
    }
  },
  created () {
    // this.getRoleList()
  }
}
</script>
<style lang="less" scoped>
</style>

<style lang="less">
// 这里相当于全局样式，控制了后台这个类的所有搜索框
// 修改了投诉表单的label
.search_from {
  .el-date-editor--daterange.el-input__inner {
    width: 230px !important;
  }
  .el-form-item {
    .el-form-item__label {
      font-weight: 700;
    }
  }
}
</style>
